package com.yunzheng.studyLeaveSystem.modules.user.leaveFunction.leave.dao;

import com.yunzheng.studyLeaveSystem.modules.user.leaveFunction.leave.entity.Leave;
import com.yunzheng.studyLeaveSystem.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * @Author: YunZheng
 * @Date: 2023/01/30/10:52
 * @Description:
 */
public class LeaveDao {
    /**
     * 添加请假信息
     * @param leave 参数为请假对象实体
     */
    public void add(Leave leave,int id){
        Connection con = null;
        PreparedStatement psm = null;
        try {
            con = DBUtils.getCon();
            String sql = "insert into leaver value(?,?,?,?,?,?,?,?)";
            psm = con.prepareStatement(sql);
            psm.setString(1,leave.getName());
            psm.setString(2,leave.getGender());
            psm.setString(3,leave.getTerm());
            psm.setString(4,leave.getDirection());
            psm.setString(5,leave.getLeave_date());
            psm.setString(6,leave.getLeave_class());
            psm.setString(7,leave.getReason());
            psm.setInt(8,id);
            psm.executeUpdate();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                DBUtils.release(null,psm,con);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("我被执行了");
    }
}